//
//  DetailsImagesView.m
//  有材网
//
//  Created by 肖扬 on 16/2/22.
//  Copyright © 2016年 肖扬. All rights reserved.
//

#import "DetailsImagesView.h"

@implementation DetailsImagesView
@synthesize mainTable,dataList;
-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.dataList = [NSMutableArray array];
        UITableView *tempTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SWIDTH, VHEIGHT - 44)];
        [tempTableView setBackgroundColor:[UIColor whiteColor]];
        [tempTableView setDelegate:self];
        [tempTableView setDataSource:self];
        self.mainTable.separatorStyle = NO;
        self.mainTable = tempTableView;
        [self addSubview:self.mainTable];
        self.mainTable.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.mainTable.tableFooterView = [[UIView alloc]init];
    }
    return self;
}
-(void)reloadTable:(NSMutableArray *)arr{
    [self.dataList removeAllObjects];
    self.dataList = arr;
    [self.mainTable reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
// 返回每一组有多少行
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataList.count;
}

// 返回哪一组的哪一行显示什么内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *tableCell =@"Cell";
    detailsImageCell* cell = (detailsImageCell*)[tableView dequeueReusableCellWithIdentifier:tableCell];
        
    if(cell == nil){
        cell = [[detailsImageCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:tableCell] ;
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    NSString *supply = [self.dataList objectAtIndex:indexPath.row];
    [cell drawImage:supply];
    return cell;
}

#pragma mark - UITableViewDelegate
// 当每一行的cell的高度不一致的时候就使用代理方法设置cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return SWIDTH/800*800+5;
}
@end


@implementation detailsImageCell

@synthesize cellImg;
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.cellImg = [[EGOImageView alloc]initWithPlaceholderImage:[UIImage imageNamed:@"缺省图"]];
        self.cellImg.frame = CGRectMake(0, 5, SWIDTH/800*800, SWIDTH/800*800);
        [self.cellImg setContentMode:UIViewContentModeScaleToFill];
        [self addSubview:self.cellImg];
    }
    return self;
}
-(void)drawImage:(NSString *)urlStr{
    [self.cellImg setImageURL:[NSURL URLWithString:urlStr]];
}
@end